#pragma once

#include <iostream>
#include <functional>
#include <vector>
#include <ctime>
#include <unistd.h>

typedef std::function<void()> task_t;

void DownLoad()
{
    std::cout << "正在进行下载" << std::endl
              << " 处理者: " << getpid() << std::endl;
}

void PrintLog()
{
    std::cout << "正在进行打印日志" << std::endl
              << " 处理者: " << getpid() << std::endl;
}

void PushVideoStream()
{
    std::cout << "正在进行推送视频流" << std::endl
              << " 处理者: " << getpid() << std::endl;
}

class Init
{
public:
    // 任务码
    const static int g_down_load_code = 0;
    const static int g_print_log_code = 1;
    const static int g_push_videostream_code = 2;
    // 任务集合
    std::vector<task_t> tasks;

public:
    Init()
    {
        tasks.push_back(DownLoad);
        tasks.push_back(PrintLog);
        tasks.push_back(PushVideoStream);

        srand(time(nullptr) ^ getpid());
    }

    bool CheckSafe(int code)
    {
        if (code <= 0 && code < tasks.size())
            return true;
        else
            return false;
    }
    void RunTask(int code)
    {
        return tasks[code]();
    }

    int SelectTask()
    {
        return rand() % tasks.size();
    }

    std::string ToDesc(int code)
    {
        switch (code)
        {
        case g_down_load_code:
            return "Download";
        case g_print_log_code:
            return "PrintLog";
        case g_push_videostream_code:
            return "PushVideoStream";
        default:
            return "Unknow";
        }
    }
};
// 定义对象
Init init;